import { Provide } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { User } from '../entity/user.entity';
import { Repository } from 'typeorm';

@Provide()
export class UserService {
  @InjectEntityModel(User)
  user: Repository<User>;

  async saveUser(params: User) {
    const result = await this.user.save(params);
    return result;
  }

  async getUser(options: Partial<User>) {
    return {
      uid: options.id,
      username: 'mockedName',
      phone: '12345678901',
      email: 'xxx.xxx@xxx.com',
    };
  }

  async listUser() {
    const list = this.user.findAndCount();
    return list;
  }
}
